import { request } from "@/utils/request";
import { mockUrlPrefix } from "@/api/baseUrl";

export function getUserList(params) {
  return request({
    url: `${mockUrlPrefix}/api/user/list`,
    params,
  });
}

export function addUser(data) {
  return request({
    url: `${mockUrlPrefix}/api/user`,
    method: "post",
    data,
  });
}

export function updateUser(data) {
  return request({
    url: `${mockUrlPrefix}/api/user`,
    method: "put",
    data,
  });
}

// data: { id: 1 }
export function deleteUser(data) {
  return request({
    url: `${mockUrlPrefix}/api/user`,
    method: "delete",
    data
  });
}

export function getUserInfoById(id) {
  return request({
    url: `${mockUrlPrefix}/api/user/detail?id=${id}`,
    method: "get",
  });
}

export function importUser() {
  return new Promise((resolve) =>
    resolve({
      data: {
        success: 0,
        failure: 2,
        total: 2,
        errors: [
          {
            row: 2,
            messages: [
              "【资源名称】值不能空",
              "【资源类型】字典值不存在",
              "【安全责任人姓名】值不能空",
            ],
          },
          {
            row: 3,
            messages: [
              "【资源名称】值不能空",
              "【资源类型】字典值不存在",
              "【安全责任人姓名】值不能空",
            ],
          },
        ],
      },
    })
  );
}
